/**
  * Created by wyc on 6/13/2017.
  */
package ninenineqs

object p08 {
  def compress_v1[T](input:List[T]):List[T] = {
    input.foldLeft(List[T]()) {
      case (Nil, x) => List(x)
      case (lst, x) if (lst .last == x) => lst
      case (lst, x) => lst ++ List(x)
    }
  }
  def compress_v2[T ](input:List[T]):List[T] = {
    input match {
      case Nil => Nil
      case h :: Nil => List(h)
      case h :: tail if (h != tail.head) => h :: compress_v2(tail)
      case _ :: tail => compress_v2(tail)

    }
  }
  def compress_v3[T ](input:List[T]):List[T] = {
    input match {
      case Nil => Nil
      case h :: tail => h :: compress_v3(tail.dropWhile(x => h==x))
    }
  }
}
